﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightControlStyle.Resources
{
    public static class ResourceDictionaryManager
    {
        // Fields
        private static readonly List<string> MResourceUrlList = new List<string>();

        // Methods
        public static void AddControlXaml(string pXamlUrl)
        {
            if (!MResourceUrlList.Contains(pXamlUrl))
            {
                Application.Current.Resources.MergedDictionaries.Add(LoadDictionary(pXamlUrl));
                MResourceUrlList.Add(pXamlUrl);
            }
        }

        public static T GetResource<T>(string pKey)
        {
            T local = default(T);
            if (Application.Current.Resources.Contains(pKey))
            {
                return (T)Application.Current.Resources[pKey];
            }
            return local;
        }

        private static ResourceDictionary LoadDictionary(string key)
        {
            return new ResourceDictionary { Source = new Uri(key, UriKind.RelativeOrAbsolute) };
        }
    }


}
